Skip to content

add an octal_to_binary converter #8940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

add an octal_to_binary converter #8940

wants to merge 1 commit into from

Conversation

RayaneQH
Copy link

@RayaneQH RayaneQH commented Aug 9, 2023

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes Feat:Octal To Binary Converter  #8921".

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Aug 9, 2023
Comment on lines +3 to +8
>>> octal_to_binary("17")
'1111'
>>> octal_to_binary("52523")
'101010101010011'
>>> octal_to_binary("532.51")
'101011010.101001'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These doctests should go inside a docstring within the function, not at the top of the file.

"""


from operator import index
Copy link
Contributor

@tianyizheng02 tianyizheng02 Aug 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from operator import index

This import is never used, and it's causing pre-commit to fail.

Comment on lines +36 to +40
if binary_string == "":
for char in dict_of_octal_to_binary[i]:
if char != "0" or indexl >= 1:
binary_string += char
indexl += 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having a special case for handling 0's at the start of the binary string, why not just append to the binary string as normal and handle the starting 0's at the very end?

"7": "111",
}
indexl = 0
for i in octal_string:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this with a comprehension instead of manually appending to a string?

@tianyizheng02
Copy link
Contributor

Closing in favor of #8949

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat:Octal To Binary Converter
2 participants